#ifndef ARRAY_H_INCLUDED
#define ARRAY_H_INCLUDED

#include <vector>
#include <iostream>

namespace prog3d {
    template <class T> class Array : public std::vector<T *> {



        public:
        Array();
        void copyFrom(const Array &p);
        T &operator()(unsigned int i);
        void allocate(unsigned int n);
        void deleteAll();
        void addEnd(T* t);
        void add(T* t);
        virtual ~Array();
        typedef typename Array<T>::iterator ItArray;
};


template <class T>void Array<T>::deleteAll() {
    for(ItArray i=this->begin();i!=this->end();i++) {
        if (*i) {delete *i; *i=NULL;}
    }
    this->clear();
}

template <class T>Array<T>::Array() {
    this->clear();
}

template <class T>Array<T>::~Array() {
    this->clear();
}



template <class T>void Array<T>::allocate(unsigned int n) {
    for(int i=0;i<n;i++) {
        push_back(new T);
    }
}

template <class T>void Array<T>::addEnd(T *t) {
	this->push_back(t);
}

template <class T>void Array<T>::add(T *t) {
	this->push_back(t);
}


template <class T>void Array<T>::copyFrom(const Array<T> &p) {
    for(unsigned int i=0;i<p.size();i++) {
        (*this)[i]->set(*p[i]);
    }
}

template <class T>T & Array<T>::operator()(unsigned int i) {
    return *(*this)[i];
}

}

#endif // ARRAY_H_INCLUDED
